//
//  GangGaoView.m
//  DJS
//
//  Created by 浪尖渝力 on 2018/2/28.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GangGaoView.h"

@implementation GangGaoView

-(void)creatView{
    self.backgroundColor=[UIColor whiteColor];
    
    _scrollView=[UIScrollView new];
    [self addSubview:_scrollView];
    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(NAV_HEIGHT);
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    _scrollView.scrollsToTop =NO;
    _scrollView.showsVerticalScrollIndicator = FALSE;
    _scrollView.showsHorizontalScrollIndicator = FALSE;
    _scrollView.bounces = NO;
    if (@available(iOS 11.0, *)) {
        self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.viewController.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    UIImageView *imageView=[UIImageView new];
    [_scrollView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(0);
        make.width.mas_equalTo(_mainW);
        make.height.mas_equalTo(_mainH*0.25);
    }];
    NSString *news_cover=[_dic objectForKey:@"carousel_img"];
    NSURL *imageURL=[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",_addressUrl,news_cover]];
    [imageView sd_setImageWithURL:imageURL];
    
    NSString *news_title=[_dic objectForKey:@"carousel_title"];
    
    CGSize size1=[ZQTools getNSStringSize:news_title andViewWight:_mainW-30 andFont:20];
    
    UILabel *titleLabel=[UILabel new];
    [_scrollView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(imageView);
        make.top.mas_equalTo(imageView.mas_bottom).mas_equalTo(20);
        make.width.mas_equalTo(_mainW-30);
    }];
    titleLabel.numberOfLines=0;
    titleLabel.text=news_title;
    titleLabel.textColor=ColorWithRGB(49, 49, 49);
    titleLabel.font=[UIFont systemFontOfSize:20];
    titleLabel.textAlignment=NSTextAlignmentCenter;
    
   
    
    NSString *news_content=[_dic objectForKey:@"carousel_content"];
    
    
    
    UILabel *contentLabel=[UILabel new];
    [_scrollView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(imageView);
        make.top.mas_equalTo(titleLabel.mas_bottom).mas_equalTo(15);
        make.width.mas_equalTo(_mainW-30);
    }];
    
    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[news_content  dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSFontAttributeName:[UIFont systemFontOfSize:25.0f] } documentAttributes:nil error:nil];
    contentLabel.attributedText = attrStr;
    contentLabel.numberOfLines=0;
    contentLabel.textColor=ColorWithRGB(99, 99, 99);
    contentLabel.font=[UIFont systemFontOfSize:18];
    
    CGSize size2=[ZQTools getNSStringSize:[NSString stringWithFormat:@"\t%@",contentLabel.text] andViewWight:_mainW-30 andFont:18];
    
    _scrollView.contentSize = CGSizeMake(0,_mainH*0.25+120+size1.height+size2.height);
}



@end
